package com.bian.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

import javax.sql.DataSource;
 
@Configuration
public class HikariDataSourceConfig {
 

    @Bean(name = "namedJdbcTemplateImpala")
    public NamedParameterJdbcTemplate namedJdbcTemplateImpala(
            @Qualifier("secondMysqlDataSource") DataSource dataSource) {
        return new NamedParameterJdbcTemplate(dataSource);
    }
    @Primary
    @Bean(name = "secondMysqlDataSource")
    @Qualifier(value = "secondMysqlDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.mysql")
    public DataSource mysqlDataSource() {
        return DataSourceBuilder.create().type(HikariDataSource.class).build();
    }

    @Bean(name = "jdbcTemplateMysql")
    public JdbcTemplate jdbcTemplateMysql(
            @Qualifier("secondMysqlDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

//    @Bean(name = "impalaDataSource")
//    @Qualifier(value = "impalaDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.impala")
//    public DataSource primaryDataSource() {
//        return DataSourceBuilder.create().type(HikariDataSource.class).build();
//    }
//
//    @Bean(name = "jdbcTemplateImpala")
//    public JdbcTemplate jdbcTemplateImpala(@Qualifier("impalaDataSource") DataSource dataSource) {
//        return new JdbcTemplate(dataSource);
//    }
}